<?
class Filter {
	var $links_visible=5;
	var $template='filter';
	var $renderAdmin=true; // где брать темплейт
	var $items;
	
	function Filter(){
		$this->items = Array();
		}
	
	function Add($title,$key,$vars){
		foreach($vars as $k=>$v)		if($_REQUEST['filter_'.$key]==$v['id']) {$vars[$k]['selected']=1;}
		$this->items[] = Array("title"=>$title,"key"=>$key,"vars"=>$vars);
		}
	
	function Render(){
		if(sizeof($this->items)==0) return "";
		// start templating
		if($this->renderAdmin)
			$temp = GetAdminTemplate($this->template);
		else
			$temp = GetSiteTemplate($this->template);
		
		$dao = Array();
		$dao["items"] = $this->items;
		return TemplaterParse($temp, $dao);
		}
		
	function GetCurrent($key){
		return $_REQUEST['filter_'.$key];
		}
}
